/* ---------------------------------------------Marlin Toolkit------------------------------------------*
Authors : Daniel Randle, Alex Bourne
Date Created : Mar 12 2013

File:
	shaderbuildwindow.cpp

Description:
	This file contains the definition for the ShaderBuildWindow class functions along with any
	helper functions associated with the class
*-------------------------------------------------------------------------------------------------------*/

// Includes
#include <global.h>
#include <logfile.h>
#include <shaderbuildwindow.h>

// Qt includes
#include <qboxlayout.h>
#include <qtoolbar.h>
#include <qaction.h>


namespace ToolkitGui
{
/*--------------------------------*
 | class ShaderBuildWindow BEGINS |
 *--------------------------------*/


ShaderBuildWindow::ShaderBuildWindow(QWidget * parent, Qt::WindowFlags f):
	QWidget(parent, f)
{
	_initObjects();
	_setupWidgets();
	_setupConnections();
}

ShaderBuildWindow::~ShaderBuildWindow()
{
}

/*---------------------------------------- PRIVATE FUNCTIONS ------------------------------------------*/
void ShaderBuildWindow::_initObjects()
{
	screen = new QTextEdit(this);
	topToolBar = new QToolBar(this);
	clrScreen = new QAction( QIcon(":/Resources/clrscreen.png"), "Clear debug screen", this);
	selectAll = new QAction( QIcon(":/Resources/selectall.png"), "Select all",this );
	copy = new QAction( QIcon(":/Resources/copy.png"), "Copy",this );
}

void ShaderBuildWindow::_setupWidgets()
{
	// Setup toolbar
	topToolBar->addAction(clrScreen);
	topToolBar->addAction(selectAll);
	topToolBar->addAction(copy);
	topToolBar->setFixedHeight(30);

	// Setup page layout
	QVBoxLayout * pageLayout = new QVBoxLayout();
	pageLayout->addWidget(topToolBar);
	pageLayout->addWidget(screen);
	pageLayout->setContentsMargins(0,0,0,0);
    pageLayout->setSpacing(0);
	setLayout(pageLayout);

	// Set starting settings
	screen->setReadOnly(true);
}

void ShaderBuildWindow::_setupConnections()
{
	connect(clrScreen, SIGNAL(triggered()), this, SLOT(onClearScreen()));
	connect(selectAll, SIGNAL(triggered()), this, SLOT(onSelectAll()));
	connect(copy, SIGNAL(triggered()), this, SLOT(onCopy()));
}


/*------------------------------------------- PRIVATE SLOTS -------------------------------------------*/

void ShaderBuildWindow::onClearScreen()
{
	clearScreen();
}

void ShaderBuildWindow::onSelectAll()
{
	screen->selectAll();
	screen->setFocus();
}

void ShaderBuildWindow::onCopy()
{
	screen->copy();
	screen->setFocus();
}


/*------------------------------------------- PUBLIC INTERFACE ---------------------------------------*/


void ShaderBuildWindow::writeToScreen(const QString & text)
{
	// newline after every entry by default with append
	screen->append(text);
}



void ShaderBuildWindow::clearScreen()
{
	screen->clear();
}


/*--------------------------------*
 | class ShaderBuildWindow ENDS   |
 *--------------------------------*/
}